<?php
declare (strict_types = 1);

namespace fortuna2;
class Auth
{
    private $encrypt_type = 'md5';
    /**
     * 验证密码
     *
     * @param [string] $input_password 用户输入密码
     * @param [string] $db_password
     * @param [string] $salt
     * @return boolval
     */
    public function verification_password($input_password, $db_password, $salt = ''): boolval{
        return $this->getMd5Password(trim($input_password),trim($salt)) === trim($db_password);
    }
    /**
     * 生成加密密码字符串
     *
     * @param [string] $input_password
     * @return array
     */
    public function encryption_password($input_password): array {
        $salt = \fortuna\Random::alnum();
        $password = $this->getMd5Password($input_password, $salt);
        return [$password, $salt];
    }
    // MD5加密密码
    protected function getMd5Password($password, $salt = '')
    {
        return md5(md5(trim($password)) . $salt);
    }
}